﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace App.Validate
{
    public class LessThanValidator:Validator
    {
        public IComparable UpperBound { get; private set; }

        public LessThanValidator(string messageTemplate, IComparable upperBound)
            : base(messageTemplate)
        {
            Guard.ArgumentNotNull(upperBound, "upperBound");
            this.UpperBound = upperBound;
        }

        public override ValidationError Validate(object objectToValidate)
        {
            if (this.UpperBound.CompareTo(objectToValidate) == 1)
            {
                return null;
            }
            else
            {
                return this.CreateValidationError(objectToValidate);
            }
        }

        public override void FormatMessage(object objectToValidate)
        {
            base.FormatMessage(objectToValidate);
            this.MessageTemplate = this.MessageTemplate.Replace("{UpperBound}", this.UpperBound.ToString());
        }
    }
}
